package org.carabiner.infinitest;

import java.util.EventObject;

/**
 * 
 * @author <a href="mailto:benrady@gmail.com"Ben Rady</a>
 */
public class TestEvent extends EventObject
{
  private static final long serialVersionUID = -1821340797590868333L;

  public enum EventType
  {
    TEST_FAILURE,
    TEST_ERROR,
    TEST_SUCCESS,
    METHOD_SUCCESS
  }
  
  private String msg;
  private String name;
  private String method;
  private EventType type;
  
  // FIXME Serializing this might be very expensive. What if the exception has references to other objects?
  private Throwable error;  
  
  public TestEvent(Object source, EventType eventType, String message, String testName, String testMethod, Throwable throwable)
  {
    super(source);
    msg = message;
    name = testName;
    method = testMethod;
    error = throwable;
    type = eventType;
  }

  public String getMessage()
  {
    return msg;
  }
  
  public String getTestName()
  {
    return name;
  }
  
  public String getTestMethod()
  {
    return method;
  }

  public Throwable getError()
  {
    return error; 
  }

  public boolean isFailure()
  {
    return error instanceof junit.framework.AssertionFailedError;
  }

  public EventType getType()
  {
    return type;
  }
}
